<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改邊角料信息')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
    <form class="form-horizontal" id="form-user-edit" th:object="${leftover}">
        <input name="tableId" type="hidden" th:field="*{tableId}"/>
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">原物料料號：</label>
                    <div class="col-sm-8">
                        <input name="materialId" placeholder="請輸入原物料料號" class="form-control" type="text" maxlength="30"
                               th:field="*{materialId}" required disabled>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">成品料號：</label>
                    <div class="col-sm-8">
                        <input name="productId" placeholder="請輸入成品料號" class="form-control" type="text" maxlength="30"
                               th:field="*{productId}" required disabled>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">邊角料料號：</label>
                    <div class="col-sm-8">
                        <input name="leftoverId" placeholder="請輸入邊角料料號" class="form-control" type="text" maxlength="30"
                               th:field="*{leftoverId}" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">賬冊：</label>
                    <div class="col-sm-8">
                        <input name="account" placeholder="請輸入賬冊" class="form-control" type="text" maxlength="30"
                               th:field="*{account}">
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">材質：</label>
                        <div class="col-sm-8">
                            <select id="material" name="material" class="form-control select2-multiple">
                                <option th:if="*{material} == null" value=""></option>
                                <option th:each="material:${materials}" th:value="${material.receiptMaterial}"
                                        th:text="${material.receiptMaterial}" th:selected="*{material} == ${material.receiptMaterial}?true:false"></option>
                            </select>
                        </div>
                    </div>
                </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">狀態：</label>
                    <div class="col-sm-8">
                        <label class="toggle-switch switch-solid">
                            <input type="checkbox" id="state" th:checked="${leftover.state == '0' ? true : false}">
                            <span></span>
                        </label>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">備案序號：</label>
                    <div class="col-sm-8">
                        <input name="recordId" placeholder="請輸入備案序號" class="form-control" type="text" maxlength="30"
                               th:field="*{recordId}">
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">可回收量：</label>
                    <div class="col-sm-8">
                        <input name="leftoverNum" placeholder="請輸入可回收量" class="form-control" type="text" maxlength="30"
                               th:field="*{leftoverNum}" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">單位：</label>
                    <div class="col-sm-8">
                        <select name="unit" class="form-control m-b"
                                th:with="type=${@dict.getType('sys_leftover_unit')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                                    th:field="*{unit}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
    var prefix = ctx + "system/leftover";

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-user-edit").serializeArray();
            var state = $("input[id='state']").is(':checked') == true ? 0 : 1;
            // var roleIds = $.form.selectCheckeds("role");
            // var postIds = $.form.selectSelects("post");
            data.push({"name": "state", "value": state});
            // data.push({"name": "roleIds", "value": roleIds});
            // data.push({"name": "postIds", "value": postIds});
            $.operate.saveTab(prefix + "/edit", data);
        }
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    $(function () {
        $('#material').select2({
            placeholder: "請選擇材質",
            allowClear: true
        });
    })
</script>
</body>
</html>